package view.components
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	public class Input extends Sprite
	{
		private var _textField:TextField;
		private var dWidth:int;
		private var dHeight:int;
		private var color:int;
		private var dAlign:String;
		private var size:int;
		
		public function Input(width:int,height:int,color:uint = 0xFFFFFF,border:Boolean = true,align:String = "left",size:int = 12)
		{
			this.size = size;
			this.color = color;
			dAlign = align;
			dWidth = width;
			dHeight = height;
			if (border)
			{
				initBg();
			}
			initText();
			
			
		}
		
		public function get textField():TextField
		{
			return _textField;
		}

		public function set selectable(v:Boolean):void
		{
			_textField.selectable = v;
		}
		
		public function set type(v:String):void
		{
			_textField.type = v;
		}
		
		private function initBg():void
		{
			with (this.graphics)
			{
				clear();
				lineStyle(1,0x444444,.5);
				beginFill(0,.7);
				drawRoundRect(0,0,dWidth,dHeight,10,10);
				endFill();
			}
		}
		
		private function initText():void
		{
			_textField = new TextField();
			
			
			var textFormat:TextFormat = new TextFormat();
			textFormat.size = size;
			textFormat.color = color;
			textFormat.indent = 5;
			textFormat.font = "Arial";
			textFormat.align = dAlign;
			_textField.defaultTextFormat = textFormat;
			addChild(_textField);
			setTextField();
		}
		
		
		public function set editable(v:Boolean):void
		{
			if (v)
			{
				_textField.type = TextFieldType.INPUT;
			}
			else
			{
				_textField.type = TextFieldType.DYNAMIC;
			}
		}
		
		public function set maxChars(v:int):void
		{
			_textField.maxChars = v;
		}
		
		private function setTextField():void
		{
			_textField.width = dWidth;
			_textField.height = dHeight;
		}
		
		override public function set width(v:Number):void
		{
			dWidth = v;
			initBg();
			setTextField();
		}			
		
		override public function set height(v:Number):void
		{
			dHeight = v;
			initBg();
			setTextField();
		}
		
		
		
		public function set text(v:String):void
		{
			_textField.text = v;
		}
		
		public function get text():String
		{
			return _textField.text;
		}
	}
}